﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.CMS.Plugins;
using MethodWorx.CMS.Services;
using System.Web.Mvc;
using MethodWorx.CMS.Content;
using MethodWorx.CMS.UI.Application.ActionResults;

namespace MethodWorx.CMS.Workflow.CreateContentItem
{
    public class CreateContentItemConfigurationController : WorkflowConfigurationController<CreateContentItemConfiguration>
    {
        private SchemaService schema;

        public CreateContentItemConfigurationController(IdeExtension view, WorkflowService service, SchemaService schema)
            : base(view, service)
        {
            this.schema = schema;
        }

        protected override WorkflowConfigurationStep CreateNewWorkflowConfigurationStep(Guid id, string output)
        {
            return new WorkflowConfigurationStep()
            {
                Id = id,
                ComponentId = CreateContentItemWorkflowComponent.ComponentId,
                ComponentConfiguration = new CreateContentItemConfiguration(),
                Output = output,
                OutputType = "ContentItem"
            };
        }

        protected override void ReconfigureExistingStep(WorkflowConfigurationStep step, string output)
        {
            step.OutputType = "ContentItem";
            if (output != null)
                step.Output = output;

            base.ReconfigureExistingStep(step, output);
        }

        protected override void OnInvokeGet(Page instance, WorkflowConfigurationStep step)
        {
            this.ViewData["contentTemplates"] =
                new SelectList(instance.Template.ContentTemplateConstraints.Select(t => t.RelatedTemplate), "Id", "Name");

            base.OnInvokeGet(instance, step);
        }

        protected override void OnInvokePost(Page instance, WorkflowConfigurationStep step)
        {
            this.OnInvokeGet(instance, step);
            base.OnInvokePost(instance, step);
        }

     
    }
}
